package com.shbaiche.bifenba.adapter.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shbaiche.bifenba.R;
import com.shbaiche.bifenba.model.match.MatchesVo;

import java.util.List;

public class SearchHotMatchAdapter extends BaseAdapter {
    private Context context;

    private List<MatchesVo> his;


    public SearchHotMatchAdapter(Context context, List<MatchesVo> his) {
        super();
        this.context = context;
        this.his = his;
    }

    public void setData(List<MatchesVo> his) {
        this.his = his;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        if (his == null)
            return 0;
        return his.size();
    }

    @Override
    public MatchesVo getItem(int arg0) {
        return his.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(final int position, View v, ViewGroup arg2) {
        ViewHolder holder = null;
        if (v == null) {
            holder = new ViewHolder();
            v = LayoutInflater.from(context).inflate(R.layout.adapter_search_hot_match, null);
            holder.name = (TextView) v.findViewById(R.id.hot_search_t_name);
            holder.time = (TextView) v.findViewById(R.id.hot_search_time);
            holder.tag = (TextView) v.findViewById(R.id.hot_search_tag);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }
        MatchesVo item = getItem(position);

        String nameStr = item.getHomeName() + "VS" + item.getVisitName();
        holder.name.setText(nameStr);
        holder.time.setText(item.getDate() + "");
        holder.tag.setText(item.getCompeteName() + "");

        return v;
    }

    class ViewHolder {
        TextView time, name, tag;
    }
}
